const {getIndex, getCount} = require('../../api/index.js')
const app = getApp()
Component({
  behaviors: [],
  properties: {
  },
  data: {
    count: 0,
    indexData: {}
  }, // 私有数据，可用于模板渲染
  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached: function () { },
    moved: function () { },
    detached: function () { },
  },
  methods: {
    getIndex() { //首页数据
      getIndex().then(res => {
        this.setData({
          indexData: res
        })
        console.log(this.data.indexData)
      })
    },
    getCount() { //商品总数
      getCount().then(res => {
        this.setData({
          count: res.goodsCount
        })
      })
    }
  },
  pageLifetimes: {
    show() {
      if (typeof this.getTabBar === 'function' && this.getTabBar()) {
        this.getTabBar().setData({
          selected: 0
        })
      }

      this.getIndex()
      this.getCount()
      // 调用app.js
      this.setData({
        inavHeight: app.globalData.inavHeight,
        inavTop: app.globalData.inavTop
      })
    }
  },
})
